package chartcreator;

import java.awt.Panel;
import java.util.ArrayList;

import javax.swing.JFrame;
import main.DataVector;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

public class ChartGenerator  {
	
	private String title;
	private ChartFrame chartFrame ;
    private JFreeChart chart;
    public ChartGenerator(String title) {
		this.title = title;

        chartFrame = new ChartFrame("rei");
        chartFrame.pack();
        chartFrame.setLocationRelativeTo(null);
        chartFrame.setBounds(0,0, 900, 690);
        chartFrame.setResizable(false);

	}
	/**
	 * Seta os dados que serao mostrados no grafico
	 * 
	 * @param dadosSeries uma lista que contem varias listas de DataVectors.
	 *
	 * @param dimensionXIndex devido ao DataVetor ter varias dimensoes, � preciso determinar qual delas ir� ser
	 * mostrada do grafico
	 * @param dimensionYIndex o mesmo de dimensioXIndex.
	 */
	public void setData(ArrayList<ArrayList<DataVector>> dadosSeries,
			int dimensionXIndex, int dimensionYIndex) {

		XYSeriesCollection dataset = new XYSeriesCollection();
		Integer cont = 1;
		for (ArrayList<DataVector> dadosSerie : dadosSeries) {

			XYSeries series = new XYSeries(cont.toString());
			cont++;
			for (DataVector data : dadosSerie) {
				series.add(data.getPosition()[dimensionXIndex], data
						.getPosition()[dimensionYIndex]);
			}
			dataset.addSeries(series);
		}
		//criando um jfrechart
		chart = ChartFactory.createScatterPlot(this.title, // title
				"X", "Y", // axis labels
				dataset, // dataset
				PlotOrientation.VERTICAL, true, // legend? yes
				true, // tooltips? yes
				false // URLs? no
				);
        chartFrame.desenhar(chart.createBufferedImage(900,653));
        chartFrame.setVisible(true);
        
      }
	
	
}
